package org.framework.edge.builder.application.impl;

import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.framework.edge.builder.application.DockerImagesApplication;
import org.springframework.web.bind.annotation.*;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.framework.edge.builder.domain.model.docker.images.DockerImages;
import org.framework.edge.builder.application.command.docker.images.DockerImagesRemoveCommand;
import org.framework.edge.builder.application.command.docker.images.DockerImagesStoryCommand;
import org.framework.edge.builder.application.command.docker.images.DockerImagesUpdateCommand;
import org.framework.edge.builder.application.command.docker.images.DockerImagesQueryListCommand;
import org.framework.edge.builder.application.command.docker.images.DockerImagesQueryOneCommand;
import org.framework.edge.builder.application.assembler.DockerImagesDTOAssembler;
import org.framework.edge.builder.application.dto.DockerImagesDTO;
import java.util.stream.Collectors;
import jakarta.annotation.Resource;
import org.framework.edge.builder.domain.model.docker.images.DockerImagesRepository;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.framework.edge.builder.application.command.docker.images.DockerImagesExcelExport;
import org.framework.edge.builder.application.command.docker.images.DockerImagesExcelImport;
/**
 * describe docker镜像 
 *
 * @author Jia wei Wu
 * @date 2025/07/10 05:16 下午
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl 
 **/
@LazyApplication
public class DockerImagesApplicationImpl implements DockerImagesApplication {

    @Resource
    DockerImagesRepository dockerImagesRepository;
    /**
     * describe 新增docker镜像
     *
     * @param dockerImagesStoryCommand 新增docker镜像     
     * @return {@link Result<DockerImages>} docker镜像新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 05:16 下午
     **/

    @Override
    public Result<DockerImages> story(DockerImagesStoryCommand dockerImagesStoryCommand) {
        DockerImages dockerImages = DockerImagesDTOAssembler.INSTANCE.toDockerImages(dockerImagesStoryCommand);
        return dockerImagesRepository.story(dockerImages);
    }
    /**
     * describe 批量新增docker镜像
     *
     * @param dockerImagesStoryCommandList 批量新增docker镜像     
     * @return {@link Result<List<DockerImages>>} docker镜像新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2025/07/10 05:16 下午
     **/

    @Override
    public Result<List<DockerImages>> batchStory(List<DockerImagesStoryCommand> dockerImagesStoryCommandList) {
        List<DockerImages> dockerImagesList = dockerImagesStoryCommandList.stream().map( DockerImagesDTOAssembler.INSTANCE::toDockerImages).collect(Collectors.toList());
        return dockerImagesRepository.batchStory(dockerImagesList);
    }
    /**
     * describe 更新docker镜像
     *
     * @param dockerImagesUpdateCommand 更新docker镜像     
     * @return {@link Result<DockerImages>} docker镜像领域对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 05:16 下午
     **/

    @Override
    public Result<DockerImages> updateOne(DockerImagesUpdateCommand dockerImagesUpdateCommand) {
        DockerImages dockerImages = DockerImagesDTOAssembler.INSTANCE.toDockerImages(dockerImagesUpdateCommand);
        return dockerImagesRepository.story(dockerImages);
    }

    /**
     * describe 查询单个docker镜像
     *
     * @param dockerImagesQueryOneCommand 查询单个docker镜像     
     * @return {@link Result<DockerImagesDTO>} docker镜像DTO对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 05:16 下午
     **/

    @Override
    public Result<DockerImagesDTO> findOne(DockerImagesQueryOneCommand dockerImagesQueryOneCommand) {
        DockerImages dockerImages = DockerImagesDTOAssembler.INSTANCE.toDockerImages(dockerImagesQueryOneCommand);
        return dockerImagesRepository.findOne(dockerImages).convert(DockerImagesDTOAssembler.INSTANCE::fromDockerImages);
    }

    /**
     * describe 查询多个docker镜像
     *
     * @param dockerImagesQueryListCommand 查询多个docker镜像     
     * @return {@link Result<List<DockerImagesDTO>>} docker镜像DTO对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 05:16 下午
     **/

    @Override
    public Result<List<DockerImagesDTO>> findList(DockerImagesQueryListCommand dockerImagesQueryListCommand) {
        DockerImages dockerImages = DockerImagesDTOAssembler.INSTANCE.toDockerImages(dockerImagesQueryListCommand);
        return dockerImagesRepository.findList(dockerImages)        .convert(dockerImagess -> dockerImagess.stream().map(DockerImagesDTOAssembler.INSTANCE::fromDockerImages).collect(Collectors.toList())) ;
    }

    /**
     * describe 分页查询多个docker镜像
     *
     * @param dockerImagesQueryListCommand 分页查询多个docker镜像     
     * @return {@link Result<LazyPage<DockerImagesDTO>>} 分页docker镜像DTO对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 05:16 下午
     **/

    @Override
    public Result<LazyPage<DockerImagesDTO>> findPage(int size,int current,DockerImagesQueryListCommand dockerImagesQueryListCommand) {
        DockerImages dockerImages = DockerImagesDTOAssembler.INSTANCE.toDockerImages(dockerImagesQueryListCommand);
        return dockerImagesRepository.findPage(size,current,dockerImages)        .convert(page -> page.convert(DockerImagesDTOAssembler.INSTANCE::fromDockerImages))            ;
    }

    /**
     * describe 删除docker镜像
     *
     * @param dockerImagesRemoveCommand 删除docker镜像     
     * @return {@link Result<DockerImages>} docker镜像     
     
     * @author Jia wei Wu
     * @date 2025/07/10 05:16 下午
     **/

    @Override
    public Result<DockerImages> remove(DockerImagesRemoveCommand dockerImagesRemoveCommand) {
     DockerImages dockerImages = DockerImagesDTOAssembler.INSTANCE.toDockerImages(dockerImagesRemoveCommand);
     return dockerImagesRepository.remove(dockerImages);
    }

    /**
     * describe 导出docker镜像
     *
     * @param dockerImagesQueryListCommand 导出docker镜像     
     * @return {@link List<DockerImagesExcelExport>} docker镜像     
     
     * @author Jia wei Wu
     * @date 2025/07/10 05:16 下午
     **/

    @Override
    public List<DockerImagesExcelExport> exportExcel(DockerImagesQueryListCommand dockerImagesQueryListCommand) {
     DockerImages dockerImages = DockerImagesDTOAssembler.INSTANCE.toDockerImages(dockerImagesQueryListCommand);
        return dockerImagesRepository.findList(dockerImages)        .applyOther(dockerImagess -> dockerImagess.stream().map(DockerImagesDTOAssembler.INSTANCE::fromDockerImagesToExcelExport).collect(Collectors.toList())) ;
    }

    /**
     * describe 导入docker镜像
     *
     * @param dockerImagesExcelImportList 导入docker镜像     
     * @return {@link Result<DockerImagesExcelImport>} docker镜像     
     
     * @author Jia wei Wu
     * @date 2025/07/10 05:16 下午
     **/

    @Override
    public Result<List<DockerImagesExcelImport>> importExcel(List<DockerImagesExcelImport> dockerImagesExcelImportList) {
        List<DockerImages> dockerImagesList = dockerImagesExcelImportList.stream().map( DockerImagesDTOAssembler.INSTANCE::toDockerImages).collect(Collectors.toList());
        dockerImagesRepository.batchStory(dockerImagesList);
        return ResultFactory.successOf(dockerImagesExcelImportList);
    }
}